<template>
  <el-dialog title="所属岗位" :visible.sync="dialogFormVisible" width="500px" @close="close" :close-on-click-modal="false">
    <!-- <vab-query-form>
      <vab-query-form-left-panel :span="12">
        <el-tooltip effect="dark" content="分配岗位" placement="top">
          <el-button icon="el-icon-plus" type="primary" @click="handleAdd"></el-button>
        </el-tooltip>
      </vab-query-form-left-panel>
    </vab-query-form> -->
    <el-table border v-loading="listLoading" :data="list" :element-loading-text="elementLoadingText">
      <!-- <el-table-column show-overflow-tooltip align="center" min-width="50" type="selection"></el-table-column> -->
      <el-table-column show-overflow-tooltip align="center" min-width="100" prop="postCode" label="编码"></el-table-column>
      <el-table-column show-overflow-tooltip align="center" min-width="100" prop="postName" label="名称"></el-table-column>
      <!-- <el-table-column show-overflow-tooltip align="center" min-width="50" label="操作">
        <template #default="{ row }">
          <el-tooltip effect="dark" content="删除当前行" placement="top">
            <el-button icon="el-icon-delete" type="danger" size="mini" circle @click="handleDelete(row)"></el-button>
          </el-tooltip>
        </template>
      </el-table-column> -->
    </el-table>
  </el-dialog>
</template>

<script>
  import { getUserPost } from '@/api/system/post'

  export default {
    name: 'UserPost',
    components: {},
    data() {
      return {
        title: '',
        listLoading: true,
        dialogFormVisible: false,
        elementLoadingText: '正在加载...',
        list: [],
        form: {
          userId: undefined,
          postId: undefined,
        },
      }
    },
    created() {},
    methods: {
      handleDelete(row) {
        if (row) {
          this.$baseConfirm('你确定要删除该用户岗位吗', null, async () => {
            await doDeleteUserPost(row.userPostId).then((res) => {
              if (res.success) {
                this.$baseMessage(res.msg, 'success')
                this.fetchData()
              } else {
                this.$baseMessage(res.msg, 'error')
              }
            })
          })
        } else {
          this.$baseMessage('未选中任何行', 'error')
          return false
        }
      },
      handleAdd() {
        this.$refs['userPostAdd'].showEdit(this.form.userId)
      },
      async fetchData() {
        this.listLoading = true
        const { data } = await getUserPost(this.form.userId)
        this.list = data
        setTimeout(() => {
          this.listLoading = false
        }, 300)
      },
      showEdit(userId) {
        this.form.userId = userId
        this.fetchData()
        this.dialogFormVisible = true
      },
      close() {
        this.form = this.$options.data().form
        this.dialogFormVisible = false
      },
      callbackFun(res) {
        if (res.success) {
          this.$baseMessage(res.msg, 'success')
          this.fetchData()
          this.close()
        } else {
          this.$baseMessage(res.msg, 'error')
        }
      },
    },
  }
</script>
